import axios from "axios";
import {Notify} from "vant";
import Vue from "vue";

axios.defaults.baseURL='http://192.168.40.177:8008';


axios.interceptors.request.use(function (config) {


    //在发送请求之前做些什么
    //获取令牌
    const token = Vue.prototype.$cookies.get("token")

    if (token) {

        config.headers["Authorization"] = "Bearer " + token

    }
    config.headers["Content-Type"] = "application/json"

    return config;
}, function (erroe) {
    // 对请求错误做些什么return Promise.reject(error);

});


//添加响应拦截器
axios.interceptors.response.use(function (res) {

    const  data = res.data

    const msg = data.msg

    const  status= data.status;

    if(status ==200){

     return  res

    }else {

        Notify(msg)
    }

},function (error) {
    //对响应错误做点什么
    return Promise.reject(error);
});
